<template>
  <div>
<h2>修改页面</h2>
<table border="1">
  <tr>
    <td>房型名称</td>
    <td>
      <input type="text" v-model="state.name">
    </td>
  </tr>
  <tr>
    <td>房型面积</td>
    <td>
      <input type="text" v-model="state.size">
    </td>
  </tr>
 
  <tr>
    <td></td>
    <td>
      <input type="button" value="修改" @click="upd">
    </td>
  </tr>
</table>
  </div>
</template>

<script setup lang="ts">
import { reactive,toRefs,onMounted } from 'vue';
import axios from 'axios';
import { useRoute,useRouter } from 'vue-router';
let route=useRoute();
let router=useRouter();
let data=reactive({
  state:{
    name:'',
    size:'',
    menDian:'',
    photo:'',
    state:'',
    isDelete:''
  },
  
})
let {state}=toRefs(data)
onMounted(()=>{
  fantian()
})

const fantian:any=()=>{
let obj={
   id:route.query.id
}
axios({
  url:'/api/Room/Fantian',
  method:'get',
  params:obj
})
.then(res=>{
  state.value=res.data.data
})
}
function upd()
{
  let obj={
    "id":route.query.id,
  "name": state.value.name,
  "size": state.value.size,
  "menDian": state.value.menDian,
  "photo": state.value.photo,
  "state": 0,
  "isDelete": true
  }
  axios({
    url:'/api/Room/Upda',
    method:'post',
    data:obj
  })
  .then(res=>{
    if(res.data.data==1)
  {
    alert("修改成功")
    router.push("../show")
  }
  
  else
  {
    alert("修改失败")
  }
  })
  .catch(err=>{

  })
}

</script>

<style scoped>

</style>